
id2doc = {}
doc2id = {}
with open("corpus.txt") as f:
    lines = f.readlines()
    for i, line in enumerate(lines):
        did = line.split(" ")[0]
        index = line.index(" ")
        document = line[index+1:]
        id2doc[did]=document.replace("\n","")
        doc2id[document.replace("\n","")]=did

srcid2docid = {}
with open("fake_test.txt") as f:
    lines2 = f.readlines()
    for i, line in enumerate(lines2):
        if i > 0:
            id = doc2id[line.replace("\n", "")]
            srcid2docid[str(i)] = id


with open("domain_result.txt") as f, open("real_relation_test.txt","w") as f2:
  lines3 = f.readlines()
  for i,line in enumerate(lines3):
      srcid = i+1
      candidate_doc = line.split(" ")
      for d in candidate_doc[:-1]:
          f2.write("0 ")
          f2.write(str(srcid2docid[str(srcid)]))
          f2.write(" T")
          f2.write(d.replace("\n",""))
          f2.write("\n")
